package com.springbootmybatiscurd.mapper.emp;

import com.springbootmybatiscurd.pojo.Emp;
import com.springbootmybatiscurd.pojo.Query;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
/*
*   -- 方案一 ：给字段起别名，让别名与实体属性一致
      select id, username, password, name, gender, image, job,
*     entrydate, create_time createTime, update_time uptadeTime
*     from table_emp ;


    //   方案二： 通过@Results,@Result注解手动映射封装
@Result({
        @Result(column = "dept_id",property = "deptId"),
        @Result(column = "creat_time",property = "updateTime"),
        @Result(column = "update_time",property = "CreateTime"),
})
@Select("select*from table_emp where id=#{id}")
public Emp getById(Integer id);
*
*     // 方案三：开启mybatis的驼峰命名自动映射开关---a_cloumn --->aCloumn
#开启mybatis的驼峰命名自动映射开关
mybatis.configuration.map-underscore-to-camel-case=true

 */

@Mapper
public interface empMapper {
    /**
     * 查询员工
     */


    // 分页查询
    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from table_emp order by update_time desc ")
    public List<Emp> listEmp();
  /*  public List<Emp> page(@Param("page")Integer page,@Param("pageSize")Integer pageSize ) ;
    // 统计数据条数
    @Select("select count(*) from table_emp")
      public long count();*/

    /**
     * 新增员工
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")// 会自动将生成的主键值封装到emp对象中
    @Insert("insert into table_emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
            "values(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})" )
    public void addEmpDao(Emp emp);


    /**
     * 删除员工
     */

    @Delete(" delete from table_emp where id=#{id}")
    public int deleteEmp(Integer id);


    /**
     * 批量删除员工
     */
    public void deleteByIds(@Param("ids") List<Integer> ids);

    /**
     * 修改员工
     */
    // 1.注解查询
   /* @Update("update table_emp set username=#{username},name=#{name}, gender=#{gender},image=#{image}," +
            " job=#{job}, entrydate=#{entrydate},deptId=#{deptId},updateTime=#{updateTime} where id=#{id}")
    public void updateEmp(Emp emp);*/
    // 2. 动态SQL查询
    public Emp updateEmp(Emp emp);


    /**
     * 查询员工
     * 注意这种必须在每个参数上加上@param
     */
    public List<Emp> queryPage(@Param("name") String name,
    @Param("gender") short gender, @Param("startTime") LocalDate startTime,@Param("endTime") LocalDate endTime );


    //方法一
  /* @Select("select *from table_emp where name like '%${name}%' and gender=#{gender} " +
           "and entrydate between #{begin} and #{end}  order by updateTime desc")
    public List<Emp> queryEmp(@Param("name") String name, @Param("gender")
   short gender, @Param("begin") LocalDate start, @Param("end") LocalDate end);*/

    // 方法二
  /* @Select("select *from table_emp where name like concat('%',#{name},'%') and gender=#{gender} " +
           "and entrydate between #{begin} and #{end}  order by updateTime desc")*/
  /* public List<Query> queryEmp(@Param("name") String name, @Param("gender")
   short gender, @Param("begin") LocalDate start, @Param("end") LocalDate end);*/
   /**
    * 查询回显员工信息
    * */
    public   Emp getByIdEmp(@Param("id") Integer id);
}


